

ac.skill('一键整理'){
    art = [[ReplaceableTextures\CommandButtons\BTNPickUpItem.blp]],
    tip = [[整理地上物品]],
    on_cast_shot = function(self)
        local hero = self.owner
        local player = hero.owner
        for it in ac.selector('item')
            : rect(player.item_rect)
            : loop()
        do
            collate_item(hero,it)
        end
    end
}


ac.skill('一键拾取'){
    art = [[ReplaceableTextures\CommandButtons\BTNPickUpItem.blp]],
    tip = [[拾取周围所有装备]],
    targettype = '点',
    range = 9999,
    is_selector = true,
    area = 300,
    on_cast_shot = function(self)
        local hero = self.owner
        local point = self.target:get_point()
        for it in ac.selector('item')
            : range(point,self.area)
            : loop()
        do
            it:give(hero)
        end
    end
}


ac.skill('一键丢弃'){
    art = [[ReplaceableTextures\CommandButtons\BTNCryptFiendBurrow.blp]],
    tip = [[将身上的装备全部丢弃到指定点]],
    targettype = '点',
    range = 9999,
    on_cast_shot = function(self)
        local hero = self.owner
        local point = self.target:get_point()
        for _,item in ipairs(hero:get_items()) do
            item:discard(point)
        end
    end
}

ac.skill('合成装备'){
    art = [[ReplaceableTextures\CommandButtons\BTNAdvStruct.blp]],
    tip = [[将地上的装备进行合成]],
    on_cast_shot = function(self)
        local hero = self.owner
        local player = hero.owner
        local items = ac.selector('item'): rect(player.item_rect): get()
        local map = {}
        for _,item in ipairs(items) do
            if not map[item.name] then
                map[item.name] = {}
            end
            table.insert(map[item.name], item)
        end
        for key,group in pairs(map) do
            local index = math.floor(#group/2)
            for i=1,index do
                local it1 = group[i*2-1]
                local it2 = group[i*2]
                hero:notify('单位-合成装备', hero, it1,it2,true)
            end 
        end
    end
}


ac.skill('助手机制'){
    on_add = function(self)
        local unit = self.owner
        local player = unit.owner
        local hero = player.hero
        self:gc(unit:event '单位-发布命令' (function(_, _, orderid, target)
            local order = Order[orderid]
            if order=='smart' then
                if unit:get_point()*target:get_point()>500 then
                    unit:issue_order('stop')
                    unit:set_point(target:get_point())
                end
            end
        end))
        
        self:gc(hero:event '单位-右键双击物品' (function(_, _, item)
            if unit:is_alive() and #unit:get_items()<6 then
                item:discard()
                item:give(unit)
            end
        end))
        self:gc(unit:event '单位-右键双击物品' (function(_, _, item)
            if hero:is_alive() and #hero:get_items()<6 then
                item:discard()
                item:give(hero)
            end
        end))
        
    end
}


--[[
物编数据
[nA0K]
_parent = "nsno"
-- 名字
Name = "助手"
-- 普通
abilList = "AInv"
-- 模型缩放
modelScale = 1.0000
-- 基础速度
spd = 522
-- 单位类别
type = "peon"
]]

register_hero(function(player,hero)
    local point = player.item_point
    local pet = player:create_unit('助手',hero:get_point())
    player.pet = pet
    pet.shop_tip = '我是一个助手'
    pet:add_restriction '无敌'
    pet:add_skill('助手机制')
    --pet:add_skill('一键整理','英雄')
    pet:add_skill('一键拾取','英雄',2)
    pet:add_skill('一键丢弃','英雄',3)
    --pet:add_skill('合成装备','英雄')
    
end)
